project(FreeEarth)
cmake_minimum_required(VERSION 2.8)

execute_process(COMMAND ${CMAKE_COMMAND} "-Wno-dev")

#设置生成动态库和静态库
if (WIN32)
    set(BUILD_SHARED_LIBS "On")
else(UNIX)
    set(BUILD_SHARED_LIBS "On")
endif()

#设置编译发布版本选项，发布新的版本需要开启此语句
#add_definitions(-DRELEASE_ON)

#设置调试库的后缀
#set(CMAKE_DEBUG_POSTFIX "d")

# FOLDER属性
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#设置库和可执行文件的输出文件
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")

include(OsgEarthMacroUtils)

IF(WIN32 AND NOT ANDROID)
	SET(LOG4_CPP_DIR ${3RD_PARTY_DIR})
	#SET(GDAL_DIR ${3rdparty})
	SET(3RD_PARTY_DIR "" CACHE PATH "Set to base lib install path")
	SET(OSG_DIR "" CACHE PATH "Set to base OpenSceneGraph install path")
	SET(OSGEARTH_DIR "" CACHE PATH "Set to OSGEARTH   install path")

	set(SILVERLINING_DIR ${3RD_PARTY_DIR})
	
	include(find_hg_osgEarth)
	include(find_hg_log4cpp)

	#include(find_hg_gdal)
	
	include_directories("${3RD_PARTY_DIR}/include")
	include_directories("${OSG_DIR}/include")
	include_directories("${OSGEARTH_DIR}/include")
	
	link_directories("${3RD_PARTY_DIR}/lib")
	link_directories("${OSG_DIR}/lib")
	link_directories("${OSGEARTH_DIR}/lib")
ENDIF()

find_package(OpenGL)
find_package(OpenSceneGraph 3.2.1 REQUIRED 
	osg 
	osgGA 
	osgDB 
	osgViewer 
	osgUtil 
	osgText 
	osgQt 
	osgVolume 
	osgTerrain 
	osgSim 
	osgFX 
	osgAnimation 
	osgManipulator
	osgParticle)

if (WIN32)
    if (OPENSCENEGRAPH_FOUND)
        include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
    else()
        MESSAGE("=========== Need Set OSG_DIR environment=============")
        MESSAGE("=========== Need Set OSG_DIR environment=============")
        MESSAGE("=========== Need Set OSG_DIR environment=============")
    endif()
endif()

if (WIN32)
    if (OSGEARTH_FOUND)
        include_directories(${OSGEARTH_INCLUDE_DIR})
    else()
        MESSAGE("=========== Need Set OSGEARTH_DIR environment=============")
        MESSAGE("=========== Need Set OSGEARTH_DIR environment=============")
        MESSAGE("=========== Need Set OSGEARTH_DIR environment=============")
    endif()
endif()

# option to install shaders:
OPTION(OSGEARTH_INSTALL_SHADERS "Whether to deploy GLSL shaders when doing a Make INSTALL" OFF)

#查找Qt
FIND_PACKAGE(Qt5Core)
FIND_PACKAGE(Qt5Widgets)
FIND_PACKAGE(Qt5Gui)
FIND_PACKAGE(Qt5OpenGL)
FIND_PACKAGE(Qt5Network)
FIND_PACKAGE(Qt5Test)
IF ( Qt5Core_FOUND AND Qt5Widgets_FOUND AND Qt5Gui_FOUND AND Qt5OpenGL_FOUND AND Qt5Network_FOUND AND Qt5Test_FOUND)
    SET(QT_INCLUDES ${Qt5Widgets_INCLUDE_DIRS} ${Qt5OpenGL_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS})
	include_directories(${QT_INCLUDES})
ELSE()
    FIND_PACKAGE(Qt4 REQUIRED QtCore QtGui QtOpenGL QtNetwork QtTest)
    IF (QT4_FOUND)
        add_definitions(-D__QT4_USE_UNICODE)
		#add_definitions(-D__UTF-8__)
        INCLUDE(${QT_USE_FILE})
                SET(QT_INCLUDES ${QT_INCLUDES} ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR}${QT_QTOPENGL_INCLUDE_DIR}${QT_QTNETWORK_INCLUDE_DIR} ${QT_QTTEST4_INCLUDE_DIR})
        SET(QT_ALL_LIBRARIES ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTWEBKIT_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTOPENGL_LIBRARY}  ${QT_QTTEST4_LIBRARY})
    ENDIF (QT4_FOUND)
ENDIF ()

if(UNIX)
	find_library(log4Cpp_DEBUG_LIBRARIES liblog4cpp.so ENV log4Cpp_LIBRARY_DIR)
	find_library(log4Cpp_RELEASE_LIBRARIES liblog4cpp.so ENV log4Cpp_LIBRARY_DIR)

	find_library(osgEarth_RELEASE_LIBRARIES libosgEarth.so ENV osgEarth_LIBRARY_DIR)
	find_library(osgEarth_DEBUG_LIBRARIES libosgEarthd.so ENV osgEarth_LIBRARY_DIR)

	find_library(osgEarthUtil_RELEASE_LIBRARIES libosgEarthUtil.so ENV osgEarth_LIBRARY_DIR)
	find_library(osgEarthUtil_DEBUG_LIBRARIES libosgEarthUtild.so ENV osgEarth_LIBRARY_DIR)

    find_library(osgEarthAnnotation_DEBUG_LIBRARIES libosgEarthAnnotationd.so ENV osgEarthAnnotation_DEBUG_LIBRARIES)
    find_library(osgEarthAnnotation_RELEASE_LIBRARIES libosgEarthAnnotation.so ENV osgEarthAnnotation_RELEASE_LIBRARIES)

    find_library(osgEarthSymbology_DEBUG_LIBRARIES libosgEarthSymbologyd.so ENV osgEarthSymbology_DEBUG_LIBRARIES)
    find_library(osgEarthSymbology_RELEASE_LIBRARIES libosgEarthSymbology.so ENV osgEarthSymbology_RELEASE_LIBRARIES)

    find_library(osgEarthFeatures_DEBUG_LIBRARIES libosgEarthFeaturesd.so ENV osgEarthSymbology_DEBUG_LIBRARIES)
    find_library(osgEarthFeatures_RELEASE_LIBRARIES libosgEarthFeatures.so ENV osgEarthSymbology_RELEASE_LIBRARIES)

endif()

#添加子项目
add_subdirectory(src)
add_subdirectory(applications)
#add_subdirectory(examples)

